﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Windows.Forms;

namespace NamazVakti
{
    public class CustomWebClient
    {
        static readonly Encoding encoding = Encoding.GetEncoding(1254);

        public static string GetResult()
        {
            string lcHtml = string.Empty;
            string postData = "sehirler=" + Parameters.SelectedCity;
            postData += ("&R1=" + Parameters.SelectedPeriod);
            postData += ("&buton=" + "buton");
            postData += ("&ulk=" + Parameters.SelectedCountry);
            byte[] data = encoding.GetBytes(postData);

            try
            {
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Parameters.DiyanetSonucSayfasi);
                myRequest.Method = "POST";
                myRequest.ContentType = "application/x-www-form-urlencoded";
                myRequest.ContentLength = data.Length;
                Stream newStream = myRequest.GetRequestStream();
                newStream.Write(data, 0, data.Length);
                newStream.Close();

                HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
                StreamReader responseStream =
                   new StreamReader(response.GetResponseStream(), encoding);
                lcHtml = responseStream.ReadToEnd();
                response.Close();
                responseStream.Close();
            }
            catch
            {
                MessageBox.Show("Web sayfası ile bağlantı kurulamadı!", "Bağlantı Hatası", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
            return lcHtml;
        }
    }
}
